package com.dinggou.shopjb.utils;

import android.util.Log;

public class LogUtil {
    public static boolean isShowingLog = true;
    private static final int LOG_MAXLENGTH = 2000;

    public static void i(String tag, String msg) {
        if (isShowingLog) {
            Log.i(tag, msg);
        }
    }

    public static void e(String tag, String msg) {
        if (isShowingLog) {
            Log.e(tag, msg);
        }
    }

    public static void d(String msg) {
        d("LOGGER", msg);
    }

    public static void d(String tag, String msg) {
        if (isShowingLog) {
            int strLength = msg.length();
            int start = 0;
            int end = LOG_MAXLENGTH;
            for (int i = 0; i < 100; i++) {
                //剩下的文本还是大于规定长度则继续重复截取并输出
                if (strLength > end) {
                    Log.d(tag + i, msg.substring(start, end));
                    start = end;
                    end = end + LOG_MAXLENGTH;
                } else {
                    Log.d(tag, msg.substring(start, strLength));
                    break;
                }
            }
        }
    }
}
